import { baseURL, request } from "../config/axios.config";

const login = async (user, t) => {
  return request.post(`/user/login?t=${t}&code=${user.code}`, user);
};

const logout = async () => {
  return request.get("/user/logout");
};

const register = async (user, t) => {
  return request.post(`/user/register?t=${t}&code=${user.code}`, user);
};

const postList = async (id) => {
  return request.get("/user/postList", { params: { id } });
};

const userInfo = async () => {
  return request.get("/user/info");
};

const userDetail = async (id) => {
  return request.get("/user/detail", {
    params: { id },
  });
};
const updateInfo = async (info) => {
  return request.post("/user/updateInfo", info);
};
const updatePassword = async (info) => {
  return request.post("/user/updatePassword", info);
};
const req2faCode = () => {
  return request.get("/user/req2faCode");
};
const loginBy2faCode = (user) => {
  const { userName } = user;
  const { tempPass: code } = user;
  return request.get("/user/loginBy2faCode", {
    params: {
      userName,
      code,
    },
  });
};
const signing = async () => {
  return request.get("/user/signing");
};
const deletePhotoWall = async (id) => {
  return request.get("/user/deletePhotoWall", {
    params: { id },
  });
};
const updatePhotoDesc = async (id, content) => {
  return request.post("/user/updatePhotoDesc", {
    id: id,
    desc: content,
  });
};

const heartbeat = async () => {
  return request.get("/user/heartBeat");
};

const scoreRank = async () => {
  return request.get("/user/scoreRank");
};

const bindMail = async (mail) => {
  return request.get(`/mail/request?toMail=${mail}`);
};
const confirmBind = async (code) => {
  return request.get(`/mail/confirm?code=${code}`);
};
const uploadURL = baseURL + "/user/upload";
const uploadPhotoWallURL = baseURL + "/user/uploadPhotoWall";

export {
  login,
  logout,
  register,
  postList,
  userInfo,
  userDetail,
  updateInfo,
  updatePassword,
  req2faCode,
  loginBy2faCode,
  signing,
  deletePhotoWall,
  updatePhotoDesc,
  heartbeat,
  scoreRank,
  bindMail,
  confirmBind,
  uploadURL,
  uploadPhotoWallURL,
};
